home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program computes a matrix - vector product, dividing the matrix into
- * blocks, with multiple elements per processor. The matrix is of size M x N,
- * where M must be a multiple of P1, and N must be a multiple of P2. */
-
- #include "dino.h"
-
- #define P1 4
- #define P2 3
- #define M 16
- #define N 9
-
- environment node[P1:id1][P2:id2] {
-
- map AllBlock = [all][block];
- map BlockAll = [block][all]; /* ==> These are examples of user defined
- mappings. The extra dimentions had
- to be used because of a deficiency in
- DINO mappings. */
-
- composite matvec (in a, in x, out y)
- double distributed a[M][N] map BlockBlock; /* Input matrix */
- double distributed x[1][N] map AllBlock; /* Input vector */
- double distributed y[M][1] map BlockAll; /* Result vector */
-
- {
- int i, j; /* Looping variable */
-
- /* Loop through the elements of y[] mapped to this procesor */
- for (i = id1 * M/P1; i < (id1 + 1) * M/P1; i++) {
-
- /* Compute the contribution of this processor to the final result */
- y[i][0] = 0;
- for (j = id2 * N/P2; j < (id2 + 1) * N/P2; j++)
- y[i][0] += a[i][j] * x[0][j];
- }
-
- /* Now, we do a sum across all processors in my row to compute the final
- * result */
- y[<id1 * M/P1,(id1 + 1) * M/P1 - 1>][0] =
- gsum(y[<id1 * M/P1,(id1 + 1) * M/P1 - 1>][0])# {node[id1][]};
- /* ==> This is an example of a reduction using
- an explicit environment set, which is
- placed in brackets after the "#" sign. */
-
- }
- }
-
- environment host {
-
- double a[M][N];
- double x[1][N];
- double y[M][1];
-
- void main ()
-
- {
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] and v[] */
- for (j = 0; j < N; j++) {
- x[0][j] = j;
- for (i = 0; i < M; i++)
- a[i][j] = i + j;
- }
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.2f", a[i][j]);
- printf ("\n");
- }
-
- printf ("\nInitial data for x:\n");
- for (i = 0; i < N; i++)
- printf ("%6.2f\n", x[0][i]);
-
- /* Perform the computation */
- matvec (a[][], x[][], y[][])#;
-
- /* Printout the resulting vector y */
- printf ("\nResult data for y:\n");
- for (i = 0; i < M; i++)
- printf ("%6.2f\n", y[i][0]);
- }
- }
-